﻿@model CategoryNavigationModel
@using Nop.Web.Models.Catalog;

@functions{
    public bool BreadCrumbContainsCurrentCategoryId(CategorySimpleModel category)
    {
        if (Model.CurrentCategoryId == 0)
            return false;

        if (category.Id == Model.CurrentCategoryId)
            return true;

        foreach (var subCategory in category.SubCategories)
        {
            if (BreadCrumbContainsCurrentCategoryId(subCategory))
            {
                return true;
            }
        }

        return false;
    }
}

@helper RenderSubCategoryLine(CategorySimpleModel category)
{    
                <li><a href="@Url.RouteUrl("Category", new { SeName = category.SeName })" >@category.Name 
                    @if (category.NumberOfProducts.HasValue)
                    {
                        <span class="pull-right">@if(category.NumberOfProducts<=9)
                                                {
                                                    @:(0@(category.NumberOfProducts.Value))
                                                }else
                                                {
                                                   @:(@(category.NumberOfProducts.Value))
                                                }</span>
                    }
                    </a></li>
            
            
        
}

@helper RenderCategoryLine(CategorySimpleModel category)
{       
    
    <div class="panel-heading">
        <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordian" href="#@category.Id">
                @if (category.Id == Model.CurrentCategoryId ||
                    category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
                    {
                        if (category.SubCategories.Count > 0)
                        {
                            <span class="badge pull-right"><i class="fa fa-plus"></i></span>
                        }
                    }

                
                <a href="@Url.RouteUrl("Category", new { SeName = category.SeName })" >@category.Name
                    @if (category.NumberOfProducts.HasValue)
                    {
                        <span class="pull-right">@if(category.NumberOfProducts<=9)
                                       {
                                           @:(0@(category.NumberOfProducts.Value))
                                       }else
                                       {
                                           @:(@(category.NumberOfProducts.Value))
                                       }</span>
                    }
                </a>
            </a>
        </h4>
    </div>

    if (category.Id == Model.CurrentCategoryId ||
        category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
    {
        if (category.SubCategories.Count > 0)
        {
            <div id="@category.Id" class="panel-collapse collapse in">
                <div class="panel-body">
                    <ul>
                        @foreach (var subCategory in category.SubCategories)
                        {
                            @RenderSubCategoryLine(subCategory)
                        }
                                
                                
                    </ul>
                </div>
            </div>

            
            
        }
    }
        
}
@if (Model.Categories.Count > 0)
{
  
    
    <h2>@T("Categories")</h2>
    <div class="panel-group category-products category-navigation-div" id="accordian">
        @foreach (var category in Model.Categories)
        {
            <div class="panel panel-default">
                        
                @RenderCategoryLine(category)
                        
            </div>
        }
        
    </div>
<!--/category-products-->

					
        









}